import heapq


# 从小到大遍历
# class Solution(object):
#     def findKthNumber(self, m, n, k):
#         """
#         :type m: int
#         :type n: int
#         :type k: int
#         :rtype: int
#         """
#         p = [1] * n
#         count = 0
#         stack = [[i + 1, i] for i in range(n)]
#         while count < k:
#             node = heapq.heappop(stack)
#             while stack and p[node[1]] > m:
#                 node = heapq.heappop(stack)
#             p[node[1]] += 1
#             heapq.heappush(stack, [(node[1] + 1) * p[node[1]], node[1]])
#             count += 1
#         return node[0]

class Solution(object):
    def findKthNumber(self, m, n, k):
        """
        :type m: int
        :type n: int
        :type k: int
        :rtype: int
        """
        def search(mid):
            return sum([min(mid // (i + 1), n) for i in range(m)])
        left = 1
        right = m * n
        while right > left:
            mid = (left + right) // 2
            now_sum = search(mid)
            if now_sum < k:
                left = mid + 1
            else:
                right = mid
        return left


data = Solution()
m = 42
n = 34
k = 401
print(data.findKthNumber(m, n, k))
